﻿@model Inscriptionem.Areas.Inscriptionem.Models.Views.CategoryCollectionViewModel

@{
    ViewBag.Title = "Inscriptionem » Categories » Order";
    Layout = "../Shared/Layout.cshtml";

    ViewBag.CurrentPage = "Categories";

    var message = string.Empty;
    
    switch(Model.Error)
    {
        case Inscriptionem.Areas.Inscriptionem.Models.Enums.OrderError.OrderNotValid:
        {
            message = "Please enter valid order, a positive number.";
            break;
        }

        case Inscriptionem.Areas.Inscriptionem.Models.Enums.OrderError.OrderDuplicate:
        {
            message = "Entered orders contains duplicates, please enter different value.";
            break;
        }
            
        case Inscriptionem.Areas.Inscriptionem.Models.Enums.OrderError.Other :
        {
            message = "Unknown error occurred, please try again.";
            break;
        }
    }
}

<div class="outer" id="contentwrap">
    @{Html.RenderPartial("NavigationMenu");}
    <div class="postcont">
		<div id="content">
            <div class="post type-post status-publish format-standard hentry">
                <h2 class="title">Order</h2>
                <div class="postdate-single error-message">@message</div>
                <form method="post" action="/Inscriptionem/Category/Order">
                    <table width="100%">
                        <thead>
                            <tr class="postdate">
                                <td>Order</td>
                                <td>Category</td>
                                <td>Section</td>
                                <td>Section Name</td>
                                <td>Language</td>
                                <td>Language Name</td>
                            </tr>
                        </thead>
                        <tbody>
                        @{int iterator = 0;}
                        @foreach(var category in Model.Categories.OrderBy(c => c.Section.Language.ID).ThenBy(c => c.Section.ID).ThenBy(c => c.ID))
                        {
                        <text>
                        <tr>
                            <td>
                                <fieldset style="border: none; margin: 0px; padding: 0px;">
                                    <input type="hidden" name="categories[@(iterator)].ID" value="@category.ID" />
                                    <input type="hidden" name="categories[@(iterator)].Section" value="@category.Section.ID" />
                                    <input type="text" name="categories[@(iterator)].Order" value="@category.Order" style="width: 50px;" />
                                </fieldset>
                            </td>
                            <td>@category.Name</td>
                            <td>@category.Section.Name</td>
                            <td>@category.Section.LocalizedName</td>
                            <td>@category.Section.Language.Name</td>
                            <td>@category.Section.Language.LocalizedName</td>
                        </tr>
                        </text>
                            iterator++;
                        }
                        </tbody>
                    </table>
                    <input type="reset" value="Reset" />&nbsp;|&nbsp;<input type="submit" value="Save" />
                </form>
			</div>
        </div>
	</div>	
</div>
